package com.ymh.config;

import com.ymh.common.domain.ResultData;
import com.ymh.util.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author: 13590
 * @date: 2020/11/8 20:27
 * @description:
 */
@Component
@Slf4j
public class RestAuthenticationEntryPoint implements ServerAuthenticationEntryPoint {

  @Override
  public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
    log.info("请求经过 RestAuthenticationEntryPoint");
    return ResponseUtils.write(exchange.getResponse(), ResultData.error(e.getMessage()));

  }
}
